package com.cskaoyan.service;

import com.cskaoyan.bean.*;
import com.cskaoyan.bean.param.CommonData;
import com.cskaoyan.bean.param.User;
import com.cskaoyan.mapper.UserMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lihaoming
 * @Description
 * @Create 2022-06-25 20:47
 * @Version
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;
    @Override
    public CommonData<User> query(String username, String mobile, BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        List<User> users = userMapper.select(username,mobile, info.getSort(), info.getOrder());
        PageInfo<User> pageInfo = new PageInfo<>(users);
        return CommonData.data(pageInfo);
    }

    @Override
    public User queryById(Integer id) {
        User user=userMapper.queryById(id);
        return user;
    }

    @Override
    public void updateByUserName(User user) {
        userMapper.updateUserByUserName(user);
    }

    @Override
    public CommonData<MarketAddress> addressList(Integer userId,String name,BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        List<MarketAddress> marketAddresses = userMapper.addressList(userId,name,info.getSort(), info.getOrder());
        PageInfo<MarketAddress> pageInfo = new PageInfo<>(marketAddresses);
        return CommonData.data(pageInfo);
    }

    @Override
    public CommonData<MarketCollect> collectList(Integer userId, Integer valueId, BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        List<MarketCollect> marketCollects = userMapper.collectList(userId,valueId,info.getSort(), info.getOrder());
        PageInfo<MarketCollect> pageInfo = new PageInfo<>(marketCollects);
        return CommonData.data(pageInfo);
    }

    @Override
    public CommonData<MarketFootprint> footPrintList(Integer userId, Integer goodsId, BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        List<MarketFootprint> marketFootprints = userMapper.footPrintList(userId,goodsId,info.getSort(), info.getOrder());
        PageInfo<MarketFootprint> pageInfo = new PageInfo<>(marketFootprints);
        return CommonData.data(pageInfo);
    }

    @Override
    public CommonData<MarketSearchHistory> historyList(Integer userId, String keyword, BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        List<MarketSearchHistory> marketSearchHistories = userMapper.historyList(userId,keyword,info.getSort(), info.getOrder());
        PageInfo<MarketSearchHistory> pageInfo = new PageInfo<>(marketSearchHistories);
        return CommonData.data(pageInfo);
    }

    @Override
    public CommonData<MarketFeedback> feedbackList(String username, Integer id, BasePageInfo info) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        List<MarketFeedback> marketFeedbacks = userMapper.feedbackList(username,id,info.getSort(), info.getOrder());
        PageInfo<MarketFeedback> pageInfo = new PageInfo<>(marketFeedbacks);
        return CommonData.data(pageInfo);
    }




}

